package com.fizzkai.p2p.core.service.impl;

import com.fizzkai.p2p.core.domain.Account;
import com.fizzkai.p2p.core.mapper.AccountMapper;
import com.fizzkai.p2p.core.service.IAccountService;
import com.fizzkai.p2p.core.util.AssertUtil;
import com.fizzkai.p2p.core.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AccountServiceImpl implements IAccountService {
    @Autowired
    private AccountMapper accountMapper;

    @Override
    public int save(Account entity) {
        return accountMapper.insert(entity);
    }

    @Override
    public int update(Account enetity) {
        int row = accountMapper.updateByPrimaryKey(enetity);
        AssertUtil.updateNotZero(row);
        return row;
    }

    @Override
    public Account get(Long id) {
        return accountMapper.selectByPrimaryKey(id);
    }

    @Override
    public Account getCurrent() {
        return accountMapper.selectByPrimaryKey(UserContext.getCurrentLoginInfo().getId());
    }
}
